from sympy import Symbol, limit

if __name__ == '__main__':
    x = Symbol("x")

    expression = (x ** 2 - 1) / (x ** 2 - 3 * x + 2)

    limit_left_1 = limit(expression, x, 1, dir="-")
    limit_right_1 = limit(expression, x, 1, dir="+")

    print("limit_left_1 = ", limit_left_1)
    print("limit_right_1 = ", limit_right_1)

    expression_value_1 = expression.subs(x, 1)
    print("expression_value_1 = ", expression_value_1)

    print(expression, "在 x = 1 的时候极限存在且相等，但是无定义。属于可去间断点")

    limit_left_2 = limit(expression, x, 2, dir="-")
    limit_right_2 = limit(expression, x, 2, dir="+")

    print("limit_left_2 = ", limit_left_2)
    print("limit_right_2 = ", limit_right_2)

    expression_value_2 = expression.subs(x, 2)
    print("expression_value_2 = ", expression_value_2)

    print(expression, "在 x = 2 的时候极限存在且不相等，但是无定义。属于第二类断点")

